﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplicationUtility
{
    public partial class Mail : Form
    {
        public Mail()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string From = txtFrom.Text;
                string To = txtTo.Text;
                string Host = txtSMTPServer.Text;
                int Port = Convert.ToInt32(txtPort.Text);

                System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage();
                Mail.To.Add(To);
                Mail.From = new System.Net.Mail.MailAddress(From);
                Mail.Subject = txtSubject.Text;
                Mail.Body = txtMessage.Text;
                Mail.IsBodyHtml = true;

                System.Net.Mail.SmtpClient Stmp = new System.Net.Mail.SmtpClient();
                Stmp.Host = Host;
                if (chkNetworkCredential.Checked)
                {
                    System.Net.NetworkCredential Credential = new System.Net.NetworkCredential();
                    Credential.UserName = txtUsername.Text;
                    Credential.Password = txtPassword.Text;
                    Stmp.UseDefaultCredentials = false;
                    Stmp.Credentials = Credential;
                }

                Stmp.Port = Port;
                try
                {
                    Stmp.Send(Mail);
                }
                catch (System.Net.Mail.SmtpException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
